<script type="text/javascript">
    function TyxxcjApplyManagerCtrl($scope, $http, modalService, CtrlUtil, $element, UploadService) {
        var ctrl = this
        CtrlUtil.build(ctrl, ':root/tyxxAudit/listTyxx')
        this.query = function () {
            if (!ctrl.cjzbQueryParam) {
                ctrl.cjzbQueryParam = $scope.mainCtrl.cjzb;
            }
            ctrl.entities && (ctrl.entities.content = {})
            var p = CtrlUtil.getQueryParams(ctrl)
            $http.post(':root/tyxxAudit/listTyxx', p).success(function (r) {
                if (r == -1) {
                    ctrl.chooseClass();
                }
                ctrl.entities = r;
            })
        }
        this.pass = function () {
            modalService.confirm('确定要通过本次采集吗？').then(function (r) {
                $http.post(':root/tyxxAudit/audit', {cjzbid: ctrl.cjzbQueryParam, pass: true}).success(function (R) {
                    $scope.mainCtrl.toQuery();
                });
            })
        }
        this.reject = function () {
            modalService.confirm('确定要退回本次采集吗？').then(function (r) {
                $http.post(':root/tyxxAudit/audit', {cjzbid: ctrl.cjzbQueryParam, pass: false}).success(function (R) {
                    $scope.mainCtrl.toQuery();
                });
            })
        }
        this.edit = function (item) {
            ctrl.add(item)
        }
        this.view = function (item) {
            ctrl.add(item, true);
        }
        this.del = function (item) {
            modalService.confirm({
                content: '确定要删除团员' + item.xm + '吗?',
                result: item
            }).then(function (r) {
                $http.post(':root/tyxxcj/deleteTyxx', r).success(function (R) {
                    modalService.succ('删除成功', 1500);
                    ctrl.query();
                })
            })

        };
        this.add = function (item, viewOnly) {
            var content = $element.find('[template]>[edit]').clone();
            var title = $element.find('[template]>[edit-title]').clone();
            var result = item, result = result || {
                cjzbid: ctrl.cjzbQueryParam,
                tgb: false,
                zbwy: false
            };
            if (!item) {
                result.adding = true;
            } else if (viewOnly) {
                result.viewOnly = true;
            } else {
                result.editing = true;
            }
            if (item) {
                //查询改组织团员信息
                $http.post(':root/tyxxcj/stu', {xh: item.xh}).success(function (r) {
                    result.tyxx = r;
                });
            }
            var method = viewOnly ? 'show' : 'confirm';
            modalService[method]({
                title: title,
                content: content,
                size: 'lg',
                titleCls: '',
                result: result,
                $scope: $scope,
                validator: function (r) {

                }
            }, {
                backdrop: false
            }).then(function (r) {
                $http.post(':root/tyxxcj/addTyxx', r).success(function (R) {
                    modalService.succ(item ? '修改成功' : '添加成功', 1500);
                    ctrl.query();
                })
            })
        }
    }

</script>
<div ng-controller="TyxxcjApplyManagerCtrl as ctrl" ng-init="ctrl.query()">
    <!-- Search area -->
    <div class="panel panel-cys">
        <div class="panel-heading">
            <h3 class="panel-title">
                <span class="glyphicon glyphicon-search"></span> 信息查询
            </h3>
        </div>
        <div class="panel-body">
            <div class="container-fluid">
                <form class="form-horizontal">
                    <div class="form-group col-md-4 remove-margin-horizontal">
                        <div class="col-md-10 col-md-offset-1">
                            <input placeholder="学号/姓名" ng-model="ctrl.xhQueryParam" type="text" class="form-control">
                            <input ng-model="ctrl.cjzbQueryParam" type="hidden" class="form-control">
                        </div>
                    </div>

                    <div class="form-group col-md-4 remove-margin-horizontal">
                        <div class="col-md-10 col-md-offset-1">
                            <div class="form-control-static">&nbsp;</div>
                        </div>
                    </div>
                </form>
                <div class="row pull-right">
                    <div class="col-md-12">
                        <button ng-click="ctrl.query()" type="submit" class="btn btn-cys btn-sm">
                            <span class="glyphicon glyphicon-search"></span>
                            查询
                        </button>
                        <button ng-click="ctrl.reset()" type="reset" class="btn btn-default btn-sm">
                            <span class="glyphicon glyphicon-repeat"></span>
                            重置
                        </button>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <!-- Search area END -->

    <!-- operation area -->
    <a ng-if="!mainCtrl.viewOnly" type="button" class="btn btn-cys btn-sm" ng-click="ctrl.add()">
        <span class="glyphicon glyphicon-plus"></span>
        新增
    </a>
    <a ng-if="!mainCtrl.viewOnly" type="button" class="btn btn-cys btn-sm" ng-click="ctrl.pass()">
        <span class="glyphicon glyphicon-export"></span>
        通过
    </a>
    <a ng-if="!mainCtrl.viewOnly" type="button" class="btn btn-cys btn-sm" ng-click="ctrl.reject()">
        <span class="glyphicon glyphicon-export"></span>
        退回
    </a>
    <a type="button" class="btn btn-cys btn-sm" ng-click="mainCtrl.toQuery()">
        <span class="glyphicon glyphicon-arrow-left"></span>
        返回
    </a>
    <div class="pull-right" ng-include="':root/components/page.html'"></div>
    <!-- operation area END -->
    <!-- data grid area -->
    <div style="padding-top: 10px;">
        <table class="table table-bordered table-hover table-striped">
            <tr>
                <th>
                    <input ng-change="ctrl.checkAll(ctrl.$checkAll)" ng-model="ctrl.$checkAll" type="checkbox"/>
                </th>
                <th>学号</th>
                <th>姓名</th>
                <th>性别</th>
                <th>出生日期</th>
                <th>民族</th>
                <th>政治面貌</th>
                <th>文化程度</th>
                <th>团干部</th>
                <th>支部委员</th>
                <th>团内职务</th>
                <th>更新状态</th>
                <th>操作</th>
            </tr>
            <tr ng-repeat="item in ctrl.entities.content">
                <td><input ng-model="item.$checked" type="checkbox"/></td>
                <td>{{item.xh}}</td>
                <td>{{item.xm}}</td>
                <td>{{item.xb.mc}}</td>
                <td>{{item.csrq | date:'yyyy-MM-dd'}}</td>
                <td>{{item.mz.mc}}</td>
                <td>{{item.zzmm.mc}}</td>
                <td>{{item.whcd.mc}}</td>
                <td>{{item.tgb | toBool}}</td>
                <td>{{item.zbwy | toBool}}</td>
                <td>{{item.tnzw}}</td>
                <td>{{item.gxzt.mc}}</td>
                <td>
                    <a ng-if="!mainCtrl.viewOnly" href="javascript:;" ng-click="ctrl.edit(item)">编辑</a>
                    <a ng-if="!mainCtrl.viewOnly" href="javascript:;" ng-click="ctrl.del(item)">删除</a>
                    <a ng-if="mainCtrl.viewOnly" href="javascript:;" ng-click="ctrl.view(item)">查看</a>
                </td>
            </tr>
        </table>
        <p>
            共有记录：
            <span>{{ctrl.entities.totalElements}}</span> 条
        </p>
    </div>
    <!-- data grid area END -->
    <div ng-non-bindable template class="hidden">
        <h3 class="panel-title" edit-title>
            <span class="glyphicon glyphicon-search"></span> 团员信息采集
        </h3>

        <div edit>
            <div class="panel-body">
                <form class="form-horizontal" ng-if="result">
                    <div class="row">
                        <data bind-ctrl="ctrl.stuxh" auto-load="true" entity="Student">
                            <filter field="xh" operator="like" value="'%'+result.tyxx.xh+'%'"/>
                        </data>
                        <data bind-ctrl="ctrl.stuname" auto-load="true" entity="Student">
                            <filter field="name" operator="like" value="'%'+result.tyxx.xm+'%'"/>
                        </data>
                        <div class="form-group">
                            <label class="col-md-2 control-label">学号:</label>
                            <div class="col-md-4" ng-if="result.adding">
                                <md-autocomplete md-no-cache="true" md-selected-item="result.tyxx"
                                                 md-search-text="ctrl.xhSearchText"
                                                 md-search-text-change="ctrl.stuxh.setFilter('xh','%'+ctrl.xhSearchText+'%','like')"
                                                 md-items="item in ctrl.stuxh.queryPage()" md-item-text="item.xh"
                                                 md-min-length="0" placeholder="输入学号搜索">
                                    <md-item-template>
                                        <span md-highlight-text="ctrl.xhSearchText"
                                              md-highlight-flags="^i">{{item.xh}}</span>
                                    </md-item-template>
                                    <md-not-found>
                                        没有找到学生
                                    </md-not-found>
                                </md-autocomplete>
                            </div>
                            <div class="col-md-4" ng-if="!result.adding">
                                <input ng-model="result.tyxx.xh" readonly="true" name="result.tyxx.xh"
                                       type="text" class="form-control">
                            </div>
                            <label class="col-md-2 control-label">姓名:</label>
                            <div class="col-md-4" ng-if="result.adding">
                                <md-autocomplete md-no-cache="true" md-selected-item="result.tyxx"
                                                 md-search-text="ctrl.nameSearchText"
                                                 md-search-text-change="ctrl.stuname.setFilter('name','%'+ctrl.nameSearchText+'%','like')"
                                                 md-items="item in ctrl.stuname.queryPage()"
                                                 md-item-text="item.name" md-min-length="0" placeholder="输入姓名搜索">
                                    <md-item-template>
                                        <span md-highlight-text="ctrl.nameSearchText" md-highlight-flags="^i">{{item.name}}</span>
                                    </md-item-template>
                                    <md-not-found>
                                        没有找到学生
                                    </md-not-found>
                                </md-autocomplete>
                            </div>
                            <div class="col-md-4" ng-if="!result.adding">
                                <input ng-model="result.tyxx.name" readonly="true" name="result.tyxx.name"
                                       type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-md-2 control-label">性别:</label>
                            <div class="col-md-4">
                                <input ng-model="result.tyxx.sexString" readonly="true" name="result.tyxx.sexString"
                                       type="text" class="form-control" placeholder="请输入性别" title="请输入性别">
                            </div>
                            <label class="col-md-2 control-label">出生日期:</label>
                            <div class="col-md-4">
                                <input ng-model="result.tyxx.birthdate" readonly="true" datetimepicker
                                       name="result.tyxx.birthdate" placeholder="请输入出生日期" title="请输入出生日期"
                                       type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-md-2 control-label">民族:</label>
                            <div class="col-md-4">
                                <input ng-model="result.tyxx.ethnicGroup.name" readonly="true"
                                       name="result.tyxx.ethnicGroup.name" placeholder="请输入民族" title="请输入民族"
                                       type="text" class="form-control">
                            </div>
                            <label class="col-md-2 control-label">文化程度:</label>
                            <div class="col-md-4">
                                <input ng-model="result.tyxx.whcd.mc" readonly="true" name="result.tyxx.whcd.mc"
                                       placeholder="请输入文化程度" title="请输入文化程度" type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-md-2 control-label">政治面貌:</label>
                            <div class="col-md-4">
                                <select class="form-control" ng-model="result.zzmm.dm" ng-disabled="result.viewOnly">
                                    <option value=""></option>
                                    <option value="01">中共党员</option>
                                    <option value="02">中共预备党员</option>
                                    <option value="03">共青团员</option>
                                    <option value="13">群众</option>
                                </select>
                            </div>
                            <label class="col-md-2 control-label">团干部:</label>
                            <div class="col-md-4 radio">
                                <input switch-handle-width="80px" bs-switch type="checkbox" ng-model="result.tgb"
                                       switch-size="small" switch-on-text="是" switch-off-text="否"
                                       name="result.tgb"/>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-md-2 control-label">支部委员:</label>
                            <div class="col-md-4">
                                <input switch-handle-width="80px" bs-switch type="checkbox" ng-model="result.zbwy"
                                       switch-size="small" switch-on-text="是" switch-off-text="否"
                                       name="result.zbwy"/>
                            </div>
                            <label class="col-md-2 control-label">团内职务:</label>
                            <div class="col-md-4 radio">
                                <input ng-model="result.tnzw" ng-readonly="result.viewOnly"
                                       name="result.tnzw" placeholder="请输入团内职务" title="请输入团内职务"
                                       type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-md-2 control-label">入团日期:</label>
                            <div class="col-md-4">
                                <input ng-model="result.rtrq" ng-readonly="result.viewOnly" name="result.rtrq"
                                       datetimepicker placeholder="请输入入团日期"
                                       title="请输入入团日期" type="text" class="form-control">
                            </div>
                            <label class="col-md-2 control-label">备注:</label>
                            <div class="col-md-4">
                                <input ng-model="result.bz" ng-readonly="result.viewOnly" name="result.bz"
                                       placeholder="请输入备注" title="请输入备注"
                                       type="text" class="form-control">
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div layout="row" layout-align="center center">
                            <h4><label>入党申请情况</label></h4>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-md-2 control-label">申请入党日期:</label>
                            <div class="col-md-4">
                                <input ng-model="result.sqrdrq" ng-readonly="result.viewOnly" name="result.sqrdrq"
                                       datetimepicker
                                       placeholder="请输入申请入党日期"
                                       title="请输入申请入党日期" type="text" class="form-control">
                            </div>
                            <label class="col-md-2 control-label">团内推优日期:</label>
                            <div class="col-md-4">
                                <input ng-model="result.tntyrq" ng-readonly="result.viewOnly" name="result.tntyrq"
                                       datetimepicker
                                       placeholder="请输入团内推优日期"
                                       title="请输入团内推优日期" type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-md-2 control-label">发展为预备党员日期:</label>
                            <div class="col-md-4">
                                <input ng-model="result.fzwybdyrq" ng-readonly="result.viewOnly" name="result.fzwybdyrq"
                                       datetimepicker
                                       placeholder="请输入发展为预备党员日期"
                                       title="请输入发展为预备党员日期" type="text" class="form-control">
                            </div>
                            <label class="col-md-2 control-label">转正日期:</label>
                            <div class="col-md-4">
                                <input ng-model="result.zzrq" ng-readonly="result.viewOnly" name="result.zzrq"
                                       datetimepicker
                                       placeholder="请输入转正日期"
                                       title="请输入转正日期" type="text" class="form-control">
                            </div>
                        </div>
                    </div>


                </form>
            </div>
        </div>

    </div>

    <div ng-non-bindable template class="hidden">
        <h3 class="panel-title" class-title>
            <span class="glyphicon glyphicon-search"></span> 选择班级
        </h3>

        <div classInfo>
            <div class="panel-body">
                <form class="form-horizontal" ng-if="result">
                    <div class="row">
                        <div class="form-group col-md-12 text-center">
                            <label class="col-md-4 control-label">名称:</label>
                            <div class="col-md-5">
                                <input ng-model="result.bjmc" name="result.bjmc" placeholder="请输入团组织名称" title="请输入团组织名称"
                                       type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>